---
title: "Creativity misinfo-India"
author: "AP"
date: "`r Sys.Date()`"
output: html_document
---
#required packages
```{r}
library(psych)
library(dplyr)
library(tidyverse)
library(summarytools)
library(ggplot2)
library(openxlsx)
```

#Arranging the dataset
```{r}
##For condition - create variable "condition" in .csv before import

crmis<- read.csv("crmis_sup.csv")
colnames(crmis)
ncol(crmis)
crmisf <- crmis %>% mutate_at(c(1:19, 22:69, 86:194, 205, 207:218), as.numeric)
sapply(crmisf, class)

crmisf <- crmisf %>%
  filter(consent == 1)

crmisf <- crmisf %>%
  filter(attention >= 1)

crmisf <- crmisf %>%
  filter(age >= 18)

#nationality frequencies
summarytools::freq(crmisf$nationality)

#nationality frequencies
summarytools::freq(crmisf$nationality)
crmisf <- crmisf %>%
  mutate(nationality_rev = ifelse(nationality %in% c(2, 3), "Non-Indians", "Indians"))
summarytools::freq(crmisf$nationality_rev)

# Ensure PID is a character column (if needed)
# Ensure PID is a character column (if needed)
crmisf <- crmisf %>%
  mutate(PID = as.character(PID))

# Recode nationality: If PID starts with "US", then "Non-Indians", else "Indians"
crmisf <- crmisf %>%
  mutate(nationality_rev2 = ifelse(str_starts(PID, "US"), "Non-Indians", "Indians"))



# Check the frequencies after the recoding
summarytools::freq(crmisf$nationality_rev2)

#Filter for Indian Data
crmisf <- crmisf %>%
  filter(nationality < 2)

#Gender Frequencies
summarytools::freq(crmisf$gender)
crmisf <- crmisf %>%
  mutate (gender_rev = recode(gender, '1' = "Man", '2' = "Woman" ,'3' = "Non-Binary/Transgender", '4' = "Prefer not to say",'5' = "Prefer to self-describe") %>%
            as.factor())
summarytools::freq(crmisf$gender_rev)

#Education Frequencies
summarytools::freq(crmisf$edu)
crmisf <- crmisf %>%
  mutate (edu_rev = recode(edu,  '1' = "Did not complete High School", '2' =  "High School Diploma/GED/12th Grade", '3' = "Associates Degree", '4' = "Bachelors Degree", '5' = "Masters Degree", '6' = "Doctorate Degree", '7' = "Prefer to self-describe") %>% 
  as.factor())
summarytools::freq(crmisf$edu_rev)

#Employment Frequencies
summarytools::freq(crmisf$employ)
crmisf <- crmisf %>%
  mutate (employ_rev = recode(employ,'1' = "Student", '2' = "Employed", '3' = "Self-employed", '4' = "Unemployed", '5' = "Retired", '6' = "Prefer to self-describe") %>% 
  as.factor())
summarytools::freq(crmisf$employ_rev)

#Reduce to Employed and Not Employed -- but check prefer to self-describe first
crmisf <- crmisf %>%
  mutate(employ_combined = ifelse(employ %in% c(1, 4, 5), "Not Employed", "Employed"))
summarytools::freq(crmisf$employ_combined)

#Marital Status Frequencies
summarytools::freq(crmisf$marital)
crmisf <- crmisf %>%
  mutate (marital_rev = recode(marital,'1' = "Single", '2' = "In a domestic partership", '3' = "Married", '4' = "Widowed/Divorced/Separated", '5' = "Prefer to self-describe") %>% 
  as.factor())
summarytools::freq(crmisf$marital_rev)

#Religion Frequencies
summarytools::freq(crmisf$religion)
crmisf <- crmisf %>%
  mutate (religion_rev = recode(religion,'1' ="Atheism", '2'= "Buddhism", '3' = "Christianity", '4' = "Hinduism", '5'= "Islam",'6' = "Jainism", '7' = "Sikhism", '8' = "Zoroastrianism", '9' = "Prefer to self-describe" , '10' = "Prefer not to disclose") %>% 
  as.factor())
summarytools::freq(crmisf$religion_rev)

##For condition - create variable "condition" in .csv before import

crmisf$condition <- as.factor(crmisf$condition)

```

#Discernment Headline Ratings
```{r}

##Pre-test ratings

crmisf <- crmisf %>%
mutate(pre_true_reliable = pre1_true_reliable + pre2_true_reliable + pre3_true_reliable + pre4_true_reliable + pre5_true_reliable + pre6_true_reliable + pre7_true_reliable + pre8_true_reliable)

crmisf <- crmisf %>%
mutate(pre_true_conf = pre1_true_conf + pre2_true_conf + pre3_true_conf + pre4_true_conf + pre5_true_conf + pre6_true_conf + pre7_true_conf + pre8_true_conf)

crmisf <- crmisf %>%
mutate(pre_true_share = pre1_true_share + pre2_true_share + pre3_true_share + pre4_true_share + pre5_true_share + pre6_true_share + pre7_true_share + pre8_true_share)

crmisf <- crmisf %>%
mutate(pre_false_reliable = pre9_false_reliable + pre10_false_reliable + pre11_false_reliable + pre12_false_reliable + pre13_false_reliable + pre14_false_reliable + pre15_false_reliable + pre16_false_reliable)

crmisf <- crmisf %>%
mutate(pre_false_conf = pre9_false_conf + pre10_false_conf + pre11_false_conf + 
pre12_false_conf + pre13_false_conf + pre14_false_conf + pre15_false_conf + pre16_false_conf)

crmisf <- crmisf %>%
mutate(pre_false_share = pre9_false_share + pre10_false_share + pre11_false_share + pre12_false_share + pre13_false_share + pre14_false_share +  pre15_false_share + pre16_false_share)

##post-test ratings

crmisf <- crmisf %>%
mutate(post_true_reliable = post1_true_reliable + post2_true_reliable + post3_true_reliable + post4_true_reliable + post5_true_reliable + post6_true_reliable + post7_true_reliable + post8_true_reliable)

crmisf <- crmisf %>%
mutate(post_true_conf = post1_true_conf + post2_true_conf + post3_true_conf + post4_true_conf + post5_true_conf + post6_true_conf + post7_true_conf + post8_true_conf)

crmisf <- crmisf %>%
mutate(post_true_share = post1_true_share + post2_true_share + post3_true_share + post4_true_share + post5_true_share + post6_true_share + post7_true_share + post8_true_share)

crmisf <- crmisf %>%
mutate(post_false_reliable = post9_false_reliable + post10_false_reliable + post11_false_reliable + post12_false_reliable + post13_false_reliable + post14_false_reliable + post15_false_reliable + post16_false_reliable)

crmisf <- crmisf %>%
mutate(post_false_conf = post9_false_conf + post10_false_conf + post11_false_conf + post12_false_conf + post13_false_conf + post14_false_conf + post15_false_conf + post16_false_conf)

crmisf <- crmisf %>%
mutate(post_false_share = post9_false_share + post10_false_share + post11_false_share + post12_false_share + post13_false_share + post14_false_share + post15_false_share + post16_false_share)

#Combined Pre-test Post-Test
crmisf <- crmisf %>%
mutate(true_reliable = pre1_true_reliable + pre2_true_reliable + pre3_true_reliable + pre4_true_reliable + pre5_true_reliable + pre6_true_reliable + pre7_true_reliable + pre8_true_reliable + post1_true_reliable + post2_true_reliable + post3_true_reliable + post4_true_reliable + post5_true_reliable + post6_true_reliable + post7_true_reliable + post8_true_reliable)

crmisf <- crmisf %>%
mutate(true_conf = pre1_true_conf + pre2_true_conf + pre3_true_conf + pre4_true_conf + pre5_true_conf + pre6_true_conf + pre7_true_conf + pre8_true_conf + post1_true_conf + post2_true_conf + post3_true_conf + post4_true_conf + post5_true_conf + post6_true_conf + post7_true_conf + post8_true_conf)

crmisf <- crmisf %>%
mutate(true_share = pre1_true_share + pre2_true_share + pre3_true_share + pre4_true_share + pre5_true_share + pre6_true_share + pre7_true_share + pre8_true_share + post1_true_share + post2_true_share + post3_true_share + post4_true_share + post5_true_share + post6_true_share + post7_true_share + post8_true_share)

crmisf <- crmisf %>%
mutate(false_reliable = pre9_false_reliable + pre10_false_reliable + pre11_false_reliable + pre12_false_reliable + pre13_false_reliable + pre14_false_reliable + pre15_false_reliable + pre16_false_reliable + post9_false_reliable + post10_false_reliable + post11_false_reliable + post12_false_reliable + post13_false_reliable + post14_false_reliable + post15_false_reliable + post16_false_reliable)

crmisf <- crmisf %>%
mutate(false_conf = pre9_false_conf + pre10_false_conf + pre11_false_conf + 
pre12_false_conf + pre13_false_conf + pre14_false_conf + pre15_false_conf + pre16_false_conf + post9_false_conf + post10_false_conf + post11_false_conf + post12_false_conf + post13_false_conf + post14_false_conf + post15_false_conf + post16_false_conf)

crmisf <- crmisf %>%
mutate(false_share = pre9_false_share + pre10_false_share + pre11_false_share + pre12_false_share + pre13_false_share + pre14_false_share +  pre15_false_share + pre16_false_share + post9_false_share + post10_false_share + post11_false_share + post12_false_share + post13_false_share + post14_false_share + post15_false_share + post16_false_share)

colnames(crmisf)
```

#inter-rater reliabilities of misinfo creation task
```{r}

```

# Descriptives
```{r}
psych::describe(crmisf)
```


#Reliabilities
```{r}

traitdecep <- crmisf %>% select(starts_with("decs"))
View(traitdecep)
psych::alpha(traitdecep)

cse <- crmisf %>% select(starts_with("cse") & !starts_with("cse_total"))
View(cse)
psych::alpha(cse)

mach <- crmisf %>% select(starts_with("mach") & !starts_with("mach_total"))
View(mach)
psych::alpha(mach)

narc <- crmisf %>% select(starts_with("narc") & !starts_with("narc_total"))
View(narc)
psych::alpha(narc)

psy <- crmisf %>% select(starts_with("psy") & !starts_with("psych_total"))
View(psy)
psych::alpha(psy)

sadism <- crmisf %>% select(starts_with("sadism") & !starts_with("sadism_total"))
View(sadism)
psych::alpha(sadism)

polid<- subset(crmisf, select=c(pi1, pi2, pi3, pi4, pi5, pi6, pi7, pi8, pi9, pi10, pi11))
View(polid)
psych::alpha(polid)

pi_cult<-subset(crmisf, select=c(pi1, pi2, pi3, pi4, pi5))
View(pi_cult)
psych::alpha(pi_cult)

pi_obed<-subset(crmisf, select=c(pi6, pi7, pi8, pi9, pi10, pi11))
View(pi_obed)
psych::alpha(pi_obed)

```

#correlations
```{r}
library(apaTables)

crmisf <- filter(crmisf, gender < 3, edu < 7,  stringsAsFactors = TRUE)

cor_misinfo <- subset(crmisf, select=c(age, gender, ses, edu,  decep_total, cse_total, mach_total, narc_total, psych_total, sadism_total, pi_total, pi_cultural_total, pi_obedience_total, pi_selfreport, pre_true_reliable, pre_true_conf, pre_true_share, pre_false_reliable, pre_false_conf, pre_false_share, post_true_reliable, post_true_conf, post_true_share, post_false_reliable, post_false_conf, post_false_share))

apa.cor.table(cor_misinfo,filename = "correl1.doc",table.number = 1, show.conf.interval = FALSE, show.sig.stars = TRUE,landscape = TRUE)
```

#Subsets for three conditions 
```{r}
misinfo <- subset(crmisf, condition == "misinfo")
psych::describe(misinfo)

depict <- subset(crmisf, condition == "depict")
psych::describe(depict)

control <- subset(crmisf, condition == "control")
psych::describe(control)
```

#H1a-c: On the pre-test for true headlines, there will be no difference in ratings of reliability (H1a), sharing intention (H1b), and confidence in judgment (H1c) between the misinformation, depict, and control conditions for true headlines.
```{r}
preanova1<- aov(pre_true_reliable~condition, data = crmisf)
tukey_preanova1 <- TukeyHSD(preanova1)
preanova2<- aov(pre_true_conf~condition, data = crmisf)
tukey_preanova2 <- TukeyHSD(preanova2)
preanova3<- aov(crmisf$pre_true_share~crmisf$condition, data = crmisf)
tukey_preanova3 <- TukeyHSD(preanova3)

summary(preanova1)
print(tukey_preanova1)
summary(preanova2)
print(tukey_preanova2)
summary(preanova3)
print(tukey_preanova3)
```
#Plots
```{r}

# Calculate means and standard errors for each variable by condition
summary_data <- crmisf %>%
  group_by(condition) %>%
  summarize(
    mean_reliable = mean(pre_true_reliable, na.rm = TRUE),
    se_reliable = sd(pre_true_reliable, na.rm = TRUE) / sqrt(n()),
    mean_share = mean(pre_true_share, na.rm = TRUE),
    se_share = sd(pre_true_share, na.rm = TRUE) / sqrt(n()),
    mean_conf = mean(pre_true_conf, na.rm = TRUE),
    se_conf = sd(pre_true_conf, na.rm = TRUE) / sqrt(n())
  )

# Plot for pre_true_reliable (no significance)
ggplot(summary_data, aes(x = condition, y = mean_reliable)) +
  geom_bar(stat = "identity", fill = "skyblue") +
  geom_errorbar(aes(ymin = mean_reliable - se_reliable, ymax = mean_reliable + se_reliable), width = 0.2) +
  labs(title = "Mean of pre_true_reliable by Condition", 
       y = "Mean pre_true_reliable", 
       x = "Condition") +
  theme_minimal()

# Plot for pre_true_share with significance line and star
ggplot(summary_data, aes(x = condition, y = mean_share)) +
  geom_bar(stat = "identity", fill = "lightgreen") +
  geom_errorbar(aes(ymin = mean_share - se_share, ymax = mean_share + se_share), width = 0.2) +
  
  # Add a line between misinfo and depict bars
  geom_segment(aes(x = 2, xend = 3, y = max(summary_data$mean_share + summary_data$se_share) + 0.5, 
                   yend = max(summary_data$mean_share + summary_data$se_share) + 0.5)) +
  
  # Add significance star above the line
  annotate("text", x = 2.5, y = max(summary_data$mean_share + summary_data$se_share) + 0.7, 
           label = "*", size = 6) +
  
  labs(title = "Mean of pre_true_share by Condition", 
       y = "Mean pre_true_share", 
       x = "Condition") +
  theme_minimal()

# Plot for pre_true_conf (no significance)
ggplot(summary_data, aes(x = condition, y = mean_conf)) +
  geom_bar(stat = "identity", fill = "lightcoral") +
  geom_errorbar(aes(ymin = mean_conf - se_conf, ymax = mean_conf + se_conf), width = 0.2) +
  labs(title = "Mean of pre_true_conf by Condition", 
       y = "Mean pre_true_conf", 
       x = "Condition") +
  theme_minimal()

# Reshape data into long format for easier plotting
long_data_pre <- summary_data %>%
  pivot_longer(cols = starts_with("mean"), names_to = "variable", values_to = "mean") %>%
  mutate(
    se = case_when(
      variable == "mean_reliable" ~ se_reliable,
      variable == "mean_share" ~ se_share,
      variable == "mean_conf" ~ se_conf
    ),
    variable = factor(variable, levels = c("mean_reliable", "mean_share", "mean_conf"),
                      labels = c("Reliability", "Sharing Intention", "Confidence"))
  )

# Create significance data frame (Only Sharing Intention Significant at 2,3)
sig_data_pre <- tibble::tibble(
  variable = factor("Sharing Intention", 
                    levels = c("Reliability", "Sharing Intention", "Confidence")),
  x = c(2),         # Start x position
  xend = c(3),      # End x position
  y = c(44),        # Lower the line (closer to bars)
  y_text = c(46),   # Y position of asterisk
  label = c("*")    # Asterisk label
)

# Facet plot for Pre-test Mean Scores (False Headlines)
ggplot(long_data_pre, aes(x = condition, y = mean)) +
  geom_bar(stat = "identity", fill = "skyblue", position = "dodge") +
  geom_errorbar(aes(ymin = mean - se, ymax = mean + se), width = 0.2) +
  facet_wrap(~ variable, scales = "free_y") +
  scale_y_continuous(limits = c(0, 100)) +  # Set y-axis limits from 0 to 100

  # Add significance line (Only for Sharing Intention, 2 -> 3)
  geom_segment(data = sig_data_pre, aes(x = x, xend = xend, y = y, yend = y), inherit.aes = FALSE) +
  geom_text(data = sig_data_pre, aes(x = (x + xend) / 2, y = y_text, label = label), size = 6) +

  labs(title = "Pre-test Mean Scores by Condition for True Headlines", 
       y = "Mean (with SE)", 
       x = "Condition") +
  theme_minimal() +
  theme(legend.position = "none")

library(tidyverse)
library(ggplot2)

# Assuming 'crmisf' contains the raw data with columns:
# 'condition', 'pre_reliable', 'pre_share', 'pre_conf'

# ----------------------------------------------------------------------
# 1. PREPARE THE RAW DATA FOR PLOTTING
# ----------------------------------------------------------------------

raw_data_long_pre <- crmisf %>%
  # Select the condition and the three pre-test variables
  select(condition, pre_true_reliable, pre_true_share, pre_true_conf) %>%
  # Reshape from wide to long format
  pivot_longer(
    cols = starts_with("pre_"),
    names_to = "variable",
    values_to = "score"
  ) %>%
  # Create a factor for variable labels (for plotting order and names)
  mutate(
    variable_label = factor(variable,
                            levels = c("pre_true_reliable", "pre_true_share", "pre_true_conf"),
                            labels = c("Reliability", "Sharing Intention", "Confidence"))
  )

# ----------------------------------------------------------------------
# 2. CREATE THE FACETED VIOLIN PLOT with JITTERED POINTS
# ----------------------------------------------------------------------

ggplot(raw_data_long_pre, aes(x = condition, y = score, fill = condition)) +

  # 1. Add the Violin Plot (density)
  geom_violin(trim = TRUE, alpha = 0.6) +

  # 2. Add Jittered Points (Raw Data)
  # Scatter points horizontally to show individual data points.
  geom_point(
    aes(color = condition), # Color points by condition
    position = position_jitter(width = 0.15, seed = 42),
    alpha = 0.2, # Transparency
    size = 1.5,
    show.legend = FALSE
  ) +

  # 3. Add the Box Plot inside (median and quartiles)
  geom_boxplot(
    width = 0.1,
    outlier.shape = NA, # Prevents plotting the outliers twice
    fill = "white",
    alpha = 0.5
  ) +

  # 4. Facet by the variable
  facet_wrap(~ variable_label, scales = "free_y") +

  # --- SIGNIFICANCE MARKERS REMOVED ---

  # 5. Set Y-axis scale (Using 0-100 limit from your original code)
  scale_y_continuous(limits = c(0, 56)) +

  # 6. Labels and Theme
  labs(
    title = "Pre-test Score Distributions by Condition for True Headlines",
    y = "Score",
    x = "Condition"
  ) +
  theme_minimal() +
  theme(
    legend.position = "none",
    plot.title = element_text(hjust = 0.5),
    strip.text = element_text(face = "bold")
  )

```
#H1d-f: On the pre-test for false headlines, there will be no difference in ratings of reliability (H1d), sharing intention (H1e), and confidence in judgment (H1f) between the misinformation, depict, and control conditions.
```{r}
preanova4<- aov(pre_false_reliable~condition, data = crmisf)
tukey_preanova4 <- TukeyHSD(preanova4)
preanova5<- aov(pre_false_conf~condition, data = crmisf)
tukey_preanova5 <- TukeyHSD(preanova5)
preanova6<- aov(pre_false_share~condition, data = crmisf)
tukey_preanova6 <- TukeyHSD(preanova6)

summary(preanova4)
print(tukey_preanova4)
summary(preanova5)
print(tukey_preanova5)
summary(preanova6)
print(tukey_preanova6)
```
```{r}
# Calculate means and standard errors for each variable by condition
summary_data_false <- crmisf %>%
  group_by(condition) %>%
  summarize(
    mean_reliable = mean(pre_false_reliable, na.rm = TRUE),
    se_reliable = sd(pre_false_reliable, na.rm = TRUE) / sqrt(n()),
    mean_share = mean(pre_false_share, na.rm = TRUE),
    se_share = sd(pre_false_share, na.rm = TRUE) / sqrt(n()),
    mean_conf = mean(pre_false_conf, na.rm = TRUE),
    se_conf = sd(pre_false_conf, na.rm = TRUE) / sqrt(n())
  )

# Plot for pre_false_reliable
ggplot(summary_data_false, aes(x = condition, y = mean_reliable)) +
  geom_bar(stat = "identity", fill = "skyblue") +
  geom_errorbar(aes(ymin = mean_reliable - se_reliable, ymax = mean_reliable + se_reliable), width = 0.2) +
  
  # Add a line between misinfo and depict bars (significant difference)
  geom_segment(aes(x = 2, xend = 3, y = max(summary_data_false$mean_reliable + summary_data_false$se_reliable) + 0.5, 
                   yend = max(summary_data_false$mean_reliable + summary_data_false$se_reliable) + 0.5)) +
  
  # Add significance star above the line
  annotate("text", x = 2.5, y = max(summary_data_false$mean_reliable + summary_data_false$se_reliable) + 0.7, 
           label = "*", size = 6) +
  
  labs(title = "Mean of pre_false_reliable by Condition", 
       y = "Mean pre_false_reliable", 
       x = "Condition") +
  scale_y_continuous(limits = c(0, 100)) +  # Set y-axis to range from 0 to 100
  theme_minimal()

# Plot for pre_false_share
ggplot(summary_data_false, aes(x = condition, y = mean_share)) +
  geom_bar(stat = "identity", fill = "lightgreen") +
  geom_errorbar(aes(ymin = mean_share - se_share, ymax = mean_share + se_share), width = 0.2) +
  
  # Add a line between misinfo and depict bars (significant difference)
  geom_segment(aes(x = 2, xend = 3, y = max(summary_data_false$mean_share + summary_data_false$se_share) + 0.5, 
                   yend = max(summary_data_false$mean_share + summary_data_false$se_share) + 0.5)) +
  
  # Add significance star above the line
  annotate("text", x = 2.5, y = max(summary_data_false$mean_share + summary_data_false$se_share) + 0.7, 
           label = "*", size = 6) +
  
  labs(title = "Mean of pre_false_share by Condition", 
       y = "Mean pre_false_share", 
       x = "Condition") +
  scale_y_continuous(limits = c(0, 100)) +  # Set y-axis to range from 0 to 100
  theme_minimal()

# Plot for pre_false_conf (no significance)
ggplot(summary_data_false, aes(x = condition, y = mean_conf)) +
  geom_bar(stat = "identity", fill = "lightcoral") +
  geom_errorbar(aes(ymin = mean_conf - se_conf, ymax = mean_conf + se_conf), width = 0.2) +
  labs(title = "Mean of pre_false_conf by Condition", 
       y = "Mean pre_false_conf", 
       x = "Condition") +
  scale_y_continuous(limits = c(0, 100)) +  # Set y-axis to range from 0 to 100
  theme_minimal()

# Reshape data into long format
long_data_pre2 <- summary_data_false %>%
  pivot_longer(cols = starts_with("mean"), names_to = "variable", values_to = "mean") %>%
  mutate(
    se = case_when(
      variable == "mean_reliable" ~ se_reliable,
      variable == "mean_share" ~ se_share,
      variable == "mean_conf" ~ se_conf
    ),
    variable = factor(variable, levels = c("mean_reliable", "mean_share", "mean_conf"),
                      labels = c("Reliability", "Sharing Intention", "Confidence"))
  )
# Create significance data frame for True Headlines
sig_data_pre2 <- tibble::tibble(
  variable = factor(c("Reliability", "Sharing Intention"),
                    levels = c("Reliability", "Sharing Intention", "Confidence")),
  x = c(2, 2),         # Start x positions (only for Reliability & Sharing Intention)
  xend = c(3, 3),      # End x positions
  y = c(44, 44),       # Lower the lines (closer to bars)
  y_text = c(46, 46),  # Y positions of asterisks
  label = c("*", "*")  # Asterisk labels
)

# Facet plot for all variables (True Headlines)
ggplot(long_data_pre2, aes(x = condition, y = mean)) +
  geom_bar(stat = "identity", fill = "lightgreen", position = "dodge") +
  geom_errorbar(aes(ymin = mean - se, ymax = mean + se), width = 0.2) +
  facet_wrap(~ variable, scales = "free_y") +
  scale_y_continuous(limits = c(0, 100)) +    # Set y-axis limits from 0 to 100

  # Add significance lines for Reliability & Sharing Intention (2,3 positions)
  geom_segment(data = sig_data_pre2, aes(x = x, xend = xend, y = y, yend = y), inherit.aes = FALSE) +
  geom_text(data = sig_data_pre2, aes(x = (x + xend) / 2, y = y_text, label = label), size = 6) +

  labs(title = "Pre-test Mean Scores by Condition for False Headlines", 
       y = "Mean (with SE)", 
       x = "Condition") +
  theme_minimal() +
  theme(legend.position = "none")

library(tidyverse)
library(ggplot2)

# Assuming 'crmisf' contains the raw data with columns:
# 'condition', 'pre_false_reliable', 'pre_false_share', 'pre_false_conf'

# ----------------------------------------------------------------------
# 1. PREPARE THE RAW DATA FOR PLOTTING
# ----------------------------------------------------------------------

raw_data_long_pre2 <- crmisf %>%
  # Select the condition and the three pre-false variables
  select(condition, pre_false_reliable, pre_false_share, pre_false_conf) %>%
  # Reshape from wide to long format
  pivot_longer(
    cols = starts_with("pre_false"),
    names_to = "variable",
    values_to = "score"
  ) %>%
  # Create a factor for variable labels (for plotting order and names)
  mutate(
    variable_label = factor(variable,
                            levels = c("pre_false_reliable", "pre_false_share", "pre_false_conf"),
                            labels = c("Reliability", "Sharing Intention", "Confidence"))
  )

# ----------------------------------------------------------------------
# 2. CREATE THE FACETED VIOLIN PLOT with JITTERED POINTS
# ----------------------------------------------------------------------

ggplot(raw_data_long_pre2, aes(x = condition, y = score, fill = condition)) +

  # 1. Add the Violin Plot (density)
  geom_violin(trim = TRUE, alpha = 0.6) +

  # 2. Add Jittered Points (Raw Data)
  # Scatter points horizontally to show individual data points.
  geom_point(
    aes(color = condition), # Color points by condition
    position = position_jitter(width = 0.15, seed = 42),
    alpha = 0.2, # Transparency
    size = 1.5,
    show.legend = FALSE
  ) +

  # 3. Add the Box Plot inside (median and quartiles)
  geom_boxplot(
    width = 0.1,
    outlier.shape = NA, # Prevents plotting the outliers twice
    fill = "white",
    alpha = 0.5
  ) +

  # 4. Facet by the variable
  facet_wrap(~ variable_label, scales = "free_y") +

  # --- SIGNIFICANCE MARKERS REMOVED ---

  # 5. Set Y-axis scale (Retaining 0-100 limit from original code)
  scale_y_continuous(limits = c(0, 56)) +

  # 6. Labels and Theme
  labs(
    title = "Pre-test Score Distributions by Condition for False Headlines",
    y = "Score",
    x = "Condition"
  ) +
  theme_minimal() +
  theme(
    legend.position = "none",
    plot.title = element_text(hjust = 0.5),
    strip.text = element_text(face = "bold")
  )
```

#H2a-c: On the post-test for true headlines, there will be an increase in ratings of reliability (H2a), sharing intention (H2b), and confidence in judgement (H2c) for the misinformation condition, as compared to the depict and control conditions.
```{r}
postanova1<- aov(post_true_reliable~condition, data = crmisf)
tukey_postanova1 <- TukeyHSD(postanova1)
postanova2<- aov(post_true_conf~condition, data = crmisf)
tukey_postanova2 <- TukeyHSD(postanova2)
postanova3<- aov(post_true_share~condition, data = crmisf)
tukey_postanova3 <- TukeyHSD(postanova3)

summary(postanova1)
print(tukey_postanova1)
summary(postanova2)
print(tukey_postanova2)
summary(postanova3)
print(tukey_postanova3)
```

```{r}

# Calculate means and standard errors
summary_data_post <- crmisf %>%
  group_by(condition) %>%
  summarize(
    mean_reliable = mean(post_true_reliable, na.rm = TRUE),
    se_reliable = sd(post_true_reliable, na.rm = TRUE) / sqrt(n()),
    mean_share = mean(post_true_share, na.rm = TRUE),
    se_share = sd(post_true_share, na.rm = TRUE) / sqrt(n()),
    mean_conf = mean(post_true_conf, na.rm = TRUE),
    se_conf = sd(post_true_conf, na.rm = TRUE) / sqrt(n())
  )

# Plot for post_true_reliable
ggplot(summary_data_post, aes(x = condition, y = mean_reliable)) +
  geom_bar(stat = "identity", fill = "skyblue") +
  geom_errorbar(aes(ymin = mean_reliable - se_reliable, ymax = mean_reliable + se_reliable), width = 0.2) +
  
  # Add significance lines and stars
  geom_segment(aes(x = 2, xend = 3, y = max(summary_data_post$mean_reliable + summary_data_post$se_reliable) + 0.5, 
                   yend = max(summary_data_post$mean_reliable + summary_data_post$se_reliable) + 0.5)) +
  annotate("text", x = 2.5, y = max(summary_data_post$mean_reliable + summary_data_post$se_reliable) + 0.7, 
           label = "*", size = 6) +
  
  labs(title = "Mean Reliability Ratings by Condition", 
       y = "Mean Reliability Rating", 
       x = "Condition") +
  scale_y_continuous(limits = c(0, max(summary_data_post$mean_reliable + summary_data_post$se_reliable) + 5)) +
  theme_minimal()

# Plot for post_true_share
ggplot(summary_data_post, aes(x = condition, y = mean_share)) +
  geom_bar(stat = "identity", fill = "lightgreen") +
  geom_errorbar(aes(ymin = mean_share - se_share, ymax = mean_share + se_share), width = 0.2) +
  
  # Add significance lines and stars
  geom_segment(aes(x = 1, xend = 2, y = max(summary_data_post$mean_share + summary_data_post$se_share) + 0.5, 
                   yend = max(summary_data_post$mean_share + summary_data_post$se_share) + 0.5)) +
  annotate("text", x = 1.5, y = max(summary_data_post$mean_share + summary_data_post$se_share) + 0.7, 
           label = "*", size = 6) +
  
  labs(title = "Mean Sharing Intention by Condition", 
       y = "Mean Sharing Intention", 
       x = "Condition") +
  scale_y_continuous(limits = c(0, max(summary_data_post$mean_share + summary_data_post$se_share) + 5)) +
  theme_minimal()


# Plot for post_true_conf (no significant difference)
ggplot(summary_data_post, aes(x = condition, y = mean_conf)) +
  geom_bar(stat = "identity", fill = "lightcoral") +
  geom_errorbar(aes(ymin = mean_conf - se_conf, ymax = mean_conf + se_conf), width = 0.2) +
  
  labs(title = "Mean Confidence in Judgement by Condition", 
       y = "Mean Confidence in Judgement", 
       x = "Condition") +
  scale_y_continuous(limits = c(0, max(summary_data_post$mean_conf + summary_data_post$se_conf) + 5)) +
  theme_minimal()

library(tidyverse)
library(ggplot2)

# Assuming 'crmisf' contains the raw data with columns:
# 'condition', 'post_true_reliable', 'post_true_share', 'post_true_conf'

# ----------------------------------------------------------------------
# 1. PREPARE THE RAW DATA FOR PLOTTING
# ----------------------------------------------------------------------

raw_data_long_true <- crmisf %>%
  # Select the condition and the three post-true variables
  select(condition, post_true_reliable, post_true_share, post_true_conf) %>%
  # Reshape from wide to long format
  pivot_longer(
    cols = starts_with("post_true"),
    names_to = "variable",
    values_to = "score"
  ) %>%
  # Create a factor for variable labels (for plotting order and names)
  mutate(
    variable_label = factor(variable,
                            levels = c("post_true_reliable", "post_true_share", "post_true_conf"),
                            labels = c("Reliability", "Sharing Intention", "Confidence"))
  )

# ----------------------------------------------------------------------
# 2. CREATE THE FACETED VIOLIN PLOT with JITTERED POINTS
# ----------------------------------------------------------------------

ggplot(raw_data_long_true, aes(x = condition, y = score, fill = condition)) +

  # 1. Add the Violin Plot (density)
  geom_violin(trim = TRUE, alpha = 0.6) +

  # 2. Add Jittered Points (Raw Data)
  geom_point(
    aes(color = condition), # Color points by condition
    position = position_jitter(width = 0.15, seed = 42),
    alpha = 0.2, # Transparency
    size = 1.5,
    show.legend = FALSE
  ) +

  # 3. Add the Box Plot inside (median and quartiles)
  geom_boxplot(
    width = 0.1,
    outlier.shape = NA, # Prevents plotting the outliers twice
    fill = "white",
    alpha = 0.5
  ) +

  # 4. Facet by the variable
  facet_wrap(~ variable_label, scales = "free_y") +

  # 5. Set Y-axis scale (UPDATED TO LIMIT 60)
  scale_y_continuous(limits = c(0, 60)) +

  # 6. Labels and Theme
  labs(
    title = "Post-test Score Distributions by Condition for True Headlines",
    y = "Score (0-60 Scale)",
    x = "Condition"
  ) +
  theme_minimal() +
  theme(
    legend.position = "none",
    plot.title = element_text(hjust = 0.5),
    strip.text = element_text(face = "bold")
  )
```
#H2d-f: On the post-test for false headlines, there will be a decrease in ratings of reliability (H2d), sharing intention (H2e), and confidence in judgement (H2f) for the misinformation condition, as compared to the depict and control conditions.

```{r}
postanova4<- aov(post_false_reliable~condition, data = crmisf)
tukey_postanova4 <- TukeyHSD(postanova4)
postanova5<- aov(post_false_conf~condition, data = crmisf)
tukey_postanova5 <- TukeyHSD(postanova5)
postanova6<- aov(post_false_share~condition, data = crmisf)
tukey_postanova6 <- TukeyHSD(postanova6)

summary(postanova4)
print(tukey_postanova4)
summary(postanova5)
print(tukey_postanova5)
summary(postanova6)
print(tukey_postanova6)
```
```{r}
library(tidyverse)
library(ggplot2)

# ----------------------------------------------------------------------
# 1. PREPARE THE RAW DATA FOR PLOTTING (No changes here)
# ----------------------------------------------------------------------

raw_data_long <- crmisf %>%
  # Select the condition and the three post-false variables
  select(condition, post_false_reliable, post_false_share, post_false_conf) %>%
  # Reshape from wide to long format
  pivot_longer(
    cols = starts_with("post_false"),
    names_to = "variable",
    values_to = "score"
  ) %>%
  # Create a factor for variable labels
  mutate(
    variable_label = factor(variable,
                            levels = c("post_false_reliable", "post_false_share", "post_false_conf"),
                            labels = c("Reliability", "Sharing Intention", "Confidence"))
  )

# ----------------------------------------------------------------------
# 2. CREATE THE FACETED VIOLIN PLOT with JITTERED POINTS
# ----------------------------------------------------------------------

ggplot(raw_data_long, aes(x = condition, y = score, fill = condition)) +

  # 1. Add the Violin Plot (density)
  geom_violin(trim = TRUE, alpha = 0.6) +

  # 2. Add Jittered Points (Raw Data)
  # position_jitter spreads the points horizontally for visibility.
  # Use 'color = "black"' or 'color = "grey"' for contrast.
  # alpha controls transparency (0.1 is very light).
  geom_point(
    aes(color = condition), # Use a color mapping, e.g., 'color = condition'
    position = position_jitter(width = 0.15, seed = 42), # Add horizontal scatter
    alpha = 0.2, # Make points transparent so the density is still visible
    size = 1.5,
    show.legend = FALSE # Hide the legend for the points
  ) +

  # 3. Add the Box Plot (to show median/quartiles)
  geom_boxplot(
    width = 0.1,
    outlier.shape = NA, # Prevents plotting the outliers twice
    fill = "white",
    alpha = 0.5
  ) +

  # 4. Split by the variable and allow independent y-axes
  facet_wrap(~ variable_label, scales = "free_y") +

  # 5. Set Y-axis scale (adjust limits as needed)
  scale_y_continuous(limits = c(0, 60)) +

  # 6. Labels and Theme
  labs(
    title = "Post-test Score Distributions by Condition for False Headlines",
    y = "Score",
    x = "Condition"
  ) +
  theme_minimal() +
  theme(
    legend.position = "none",
    plot.title = element_text(hjust = 0.5),
    strip.text = element_text(face = "bold")
  )


# ----------------------------------------------------------------------
# 1. PREPARE THE RAW DATA FOR PLOTTING
# ----------------------------------------------------------------------

raw_data_long_true <- crmisf %>%
  # Select the condition and the three post-true variables
  select(condition, post_true_reliable, post_true_share, post_true_conf) %>%
  # Reshape from wide to long format
  pivot_longer(
    cols = starts_with("post_true"),
    names_to = "variable",
    values_to = "score"
  ) %>%
  # Create a factor for variable labels (for plotting order and names)
  mutate(
    variable_label = factor(variable,
                            levels = c("post_true_reliable", "post_true_share", "post_true_conf"),
                            labels = c("Reliability", "Sharing Intention", "Confidence"))
  )

# ----------------------------------------------------------------------
# 2. CREATE THE FACETED VIOLIN PLOT with JITTERED POINTS
# ----------------------------------------------------------------------

ggplot(raw_data_long_true, aes(x = condition, y = score, fill = condition)) +

  # 1. Add the Violin Plot (density)
  geom_violin(trim = TRUE, alpha = 0.6) +

  # 2. Add Jittered Points (Raw Data)
  geom_point(
    aes(color = condition), # Color points by condition
    position = position_jitter(width = 0.15, seed = 42),
    alpha = 0.2, # Transparency
    size = 1.5,
    show.legend = FALSE
  ) +

  # 3. Add the Box Plot inside (median and quartiles)
  geom_boxplot(
    width = 0.1,
    outlier.shape = NA, # Prevents plotting the outliers twice
    fill = "white",
    alpha = 0.5
  ) +

  # 4. Facet by the variable
  facet_wrap(~ variable_label, scales = "free_y") +

  # 5. Set Y-axis scale (UPDATED TO LIMIT 60)
  scale_y_continuous(limits = c(0, 60)) +

  # 6. Labels and Theme
  labs(
    title = "Post-test Score Distributions by Condition for True Headlines",
    y = "Score (0-60 Scale)",
    x = "Condition"
  ) +
  theme_minimal() +
  theme(
    legend.position = "none",
    plot.title = element_text(hjust = 0.5),
    strip.text = element_text(face = "bold")
  )

library(tidyverse)
library(ggplot2)

# Assuming 'crmisf' contains the raw data with columns:
# 'condition', 'post_true_reliable', 'post_true_share', 'post_true_conf',
# 'post_false_reliable', 'post_false_share', 'post_false_conf'
# ----------------------------------------------------------------------
# 1. DATA PREPARATION AND RESTRUCTURING
# ----------------------------------------------------------------------

library(tidyverse)
library(ggplot2)

# Assuming 'crmisf' contains the raw data with columns:
# 'condition', 'post_true_reliable', 'post_true_share', 'post_true_conf',
# 'post_false_reliable', 'post_false_share', 'post_false_conf'

# ----------------------------------------------------------------------
# 1. DATA PREPARATION AND RESTRUCTURING
# ----------------------------------------------------------------------

# Select and reshape the TRUE headline data
true_data_long <- crmisf %>%
  select(condition, starts_with("post_true")) %>%
  pivot_longer(
    cols = starts_with("post_true"),
    names_to = "variable",
    values_to = "score"
  ) %>%
  mutate(
    Veracity = "True Headlines",
    variable = str_remove(variable, "post_true_")
  )

# Select and reshape the FALSE headline data
false_data_long <- crmisf %>%
  select(condition, starts_with("post_false")) %>%
  pivot_longer(
    cols = starts_with("post_false"),
    names_to = "variable",
    values_to = "score"
  ) %>%
  mutate(
    Veracity = "False Headlines",
    variable = str_remove(variable, "post_false_")
  )

# Combine and set factor orders
combined_data_long <- bind_rows(true_data_long, false_data_long) %>%
  # CORRECTED: Veracity levels now match the data labels (Headlines - plural)
  mutate(
    Veracity = factor(Veracity, levels = c("True Headlines", "False Headlines")), # TRUE comes first
    variable_label = factor(variable,
                            levels = c("reliable", "share", "conf"),
                            labels = c("Reliability", "Sharing Intention", "Confidence"))
  )

# ----------------------------------------------------------------------
# 2. CREATE THE FACETED VIOLIN PLOT (Post-test)
# ----------------------------------------------------------------------

ggplot(combined_data_long, aes(x = condition, y = score, fill = condition)) +

  # 1. Add the Violin Plot (density)
  geom_violin(trim = TRUE, alpha = 0.6) +

  # 2. Add Jittered Points (Raw Data)
  geom_point(
    aes(color = condition),
    position = position_jitter(width = 0.15, seed = 42),
    alpha = 0.15,
    size = 1.5,
    show.legend = FALSE
  ) +

  # 3. Add the Box Plot inside (median and quartiles)
  geom_boxplot(
    width = 0.1,
    outlier.shape = NA,
    fill = "white",
    alpha = 0.5
  ) +

  # 4. Facet by both Veracity (rows) and Variable (columns)
  facet_grid(Veracity ~ variable_label, scales = "free_y") +

  # 5. Set Y-axis scale
  scale_y_continuous(limits = c(0, 60)) +

  # 6. Labels and Theme
  labs(
    title = "Post-test Score Distributions by Condition for True and False Headlines",
    y = "Score",
    x = "Condition"
  ) +
  theme_minimal() +
  theme(
    legend.position = "right", # Added Legend
    plot.title = element_text(hjust = 0.5),
    strip.text = element_text(face = "bold")
  )

# ----------------------------------------------------------------------
# 1. DATA PREPARATION AND RESTRUCTURING (Pre-test)
# ----------------------------------------------------------------------

# Select and reshape the TRUE headline data
pre_true_data <- crmisf %>%
  select(condition, starts_with("pre_true")) %>%
  pivot_longer(
    cols = starts_with("pre_true"),
    names_to = "variable",
    values_to = "score"
  ) %>%
  mutate(
    Veracity = "True Headlines",
    variable = str_remove(variable, "pre_true_")
  )

# Select and reshape the FALSE headline data
pre_false_data <- crmisf %>%
  select(condition, starts_with("pre_false")) %>%
  pivot_longer(
    cols = starts_with("pre_false"),
    names_to = "variable",
    values_to = "score"
  ) %>%
  mutate(
    Veracity = "False Headlines",
    variable = str_remove(variable, "pre_false_")
  )

# Combine and set factor orders
combined_pre_data <- bind_rows(pre_true_data, pre_false_data) %>%
  # CORRECTED: Veracity levels now match the data labels (Headlines - plural)
  mutate(
    Veracity = factor(Veracity, levels = c("True Headlines", "False Headlines")), # TRUE comes first
    variable_label = factor(variable,
                            levels = c("reliable", "share", "conf"),
                            labels = c("Reliability", "Sharing Intention", "Confidence"))
  )

# ----------------------------------------------------------------------
# 2. CREATE THE FACETED VIOLIN PLOT (Pre-test)
# ----------------------------------------------------------------------

ggplot(combined_pre_data, aes(x = condition, y = score, fill = condition)) +

  # 1. Add the Violin Plot (density)
  geom_violin(trim = TRUE, alpha = 0.6) +

  # 2. Add Jittered Points (Raw Data)
  geom_point(
    aes(color = condition),
    position = position_jitter(width = 0.15, seed = 42),
    alpha = 0.15,
    size = 1.5,
    show.legend = FALSE
  ) +

  # 3. Add the Box Plot inside (median and quartiles)
  geom_boxplot(
    width = 0.1,
    outlier.shape = NA,
    fill = "white",
    alpha = 0.5
  ) +

  # 4. Facet by both Veracity (rows) and Variable (columns)
  facet_grid(Veracity ~ variable_label, scales = "free_y") +

  # 5. Set Y-axis scale
  scale_y_continuous(limits = c(0, 60)) +

  # 6. Labels and Theme
  labs(
    title = "Pre-test Score Distributions by Condition for True and False Headlines",
    y = "Score",
    x = "Condition"
  ) +
  theme_minimal() +
  theme(
    legend.position = "right", # Added Legend
    plot.title = element_text(hjust = 0.5),
    strip.text = element_text(face = "bold")
  )
```



